package com.service.impl;

import com.dao.UserDao;
import com.pojo.*;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;


    /**
     * 分页查询数据
     * @param current
     * @param size
     * @param username
     * @return
     */
    @Override
    public PageBean findUserAll(Integer current, Integer size,String username) {
        System.out.println("是否进入了");
        System.out.println(current);
        System.out.println(size);
        System.out.println(username);
        int begin= (current-1)*size;
        List<User> userList = userDao.findUserList(begin, size, username);
        int count = userDao.getCount(username);
        System.out.println(userList);
        return  new PageBean(userList,count,current,size);
    }

    @Override
    public User login(String username, String password) {
        User user = userDao.login(username);
        if(user!=null){
            if(user.getPassword().equals(password)){
                return user;
            }

        }
        return null;
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

}
